﻿using System.Collections;
using System.Collections.Generic;
using UBlockly.Scriptable;
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Object = UnityEngine.Object;

namespace UBlockly.Compotent
{
    internal interface IParamSelectHandler : ISelectHandler
    {
        Action<IParamGetterCompotent> ParamSelectHandler { set; }
    }

    internal interface IParamDeselectHandler : IDeselectHandler
    {
        Action<IParamGetterCompotent> ParamDeselectHandler { set; }
    }

    public abstract class IParamGetterCompotent : Selectable,IInputGetter,IParamSelectHandler,IParamDeselectHandler
    {
        private IVarObject value;
        public Action<IParamGetterCompotent> ParamSelectHandler { private get; set; }

        public Action<IParamGetterCompotent> ParamDeselectHandler { private get; set; }

        public abstract Type ValueType { get; }
        public object GetterValue()
        {
            return InputGetter() ?? value;
        }

        public virtual void SetDisplayValue(string value)
        {
            
        }

        internal void SetVarObjectValue(IVarObject obj)
        {
            value = obj;
        }

        protected virtual object InputGetter()
        {
            return null;
        }

        protected virtual void OnParamSelected(BaseEventData eventData)
        {
            ParamSelectHandler?.Invoke(this);
        }

        protected virtual void OnParamDeselected(BaseEventData eventData)
        {
            ParamDeselectHandler?.Invoke(this);
        }
        void ISelectHandler.OnSelect(BaseEventData eventData)
        {
            OnParamSelected(eventData);
        }

        void IDeselectHandler.OnDeselect(BaseEventData eventData)
        {
            OnParamDeselected(eventData);
        }
    }
}
